<template>
	<view id="selector-area1">
		<uni-collapse v-if="areaList.length !== 1" accordion v-model="currentTab" @change="open">
			<uni-collapse-item v-for="(item,index) in areaList" :name="item.id" :key="index" :title="item.areaName">
				<template v-slot:title>
					<view class="v-selector-title">
						<image class="img" src="https://bc-staticfiles.oss-cn-zhangjiakou.aliyuncs.com/wechat/layer2.png"></image>
						{{item.areaName}}
					</view>
				</template>
				<u-cell isLink icon="https://bc-staticfiles.oss-cn-zhangjiakou.aliyuncs.com/wechat/layer3.png" :title="item.areaName" @click="backPage(item.id, item.areaName)"></u-cell>
				<scroll-view scroll-y="true" :style="{ 'height': '400px' }">
					<u-cell isLink icon="https://bc-staticfiles.oss-cn-zhangjiakou.aliyuncs.com/wechat/layer4.png" v-for="(son, i) in item.children" :title="son.areaName" :key="i" @click="backPage(son.id, son.areaName)"></u-cell>
				</scroll-view>
			</uni-collapse-item>
		</uni-collapse>
		<u-cell v-else isLink icon="https://bc-staticfiles.oss-cn-zhangjiakou.aliyuncs.com/wechat/layer3.png" :title="areaList[0].areaName" @click="backPage(areaList[0].id, areaList[0].areaName)"></u-cell>
	</view>
</template>

<script>
	import { AREA_ID } from '@/store/mutaction-types'
	import { getAllArea, getAreaList } from '@/api/global'
	export default {
		props: {
			params: {
				type: Object,
				default: () => {}
			},
			type: {
				type: String,
				default: 'one'
			}
		},
		data () {
			return {
				currentTab: '',
				areaList: [],
				selectItem: {}
			}
		},
		mounted() {
			this.getList()
		},
		methods: {
			open (e) {},
			getList() {
				uni.showLoading({
					title: '数据加载中',
					mask: true
				})
				if (this.type === 'one') {
					getAreaList().then(res => {
						this.areaList = res.data.data
						uni.hideLoading()
					})
				} else {
					getAllArea().then(res => {
						this.areaList = res.data.data
						uni.hideLoading()
					})
				}
			},
			backPage (id, name) {
				console.log(id, name)
				this.selectItem['areaId'] = id
				this.selectItem['areaName'] = name
				this.$emit('onselect', this.selectItem)
			}
		}
	}
</script>

<style>
	.v-selector-title {
		display: flex;
		justify-content: start;
		align-items: center;
		padding: 20upx 0 20upx 20upx;
		font-size: 32upx;
	}
	.img {
		width: 40upx;
		height: 40upx;
		margin-right: 10upx;
	}
</style>